#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <limits.h>
#include <string.h>
#include <unistd.h>

#define EMPTY false
#define OCCUPY true
typedef struct MAXHEAP Heap;
typedef struct HASHTABLE HashTable;
typedef struct ELEMENTTYPE ElementType;

struct ELEMENTTYPE{
	int Key;
	int Pos;
	_Bool Used;
};
struct MAXHEAP{
	ElementType *Elm;
	int Size;
};
struct HASHTABLE{
	int *Key;
	int TableSize;
	_Bool *Info;
};

Heap *HeapInit(int Size);
void HeapSort(Heap*,int(*)(ElementType,ElementType));
void BuildHeap(Heap *h,int(*cmp)(ElementType,ElementType));
int HeapCmp(ElementType,ElementType);
void DestroyHeap(Heap*);
HashTable *HashTableInit(int TableSize);
int HashValue(HashTable*,int);
int InsertPos(HashTable*,int);
void Insert(HashTable*,int,int);
void DestroyHashTable(HashTable*);
void PrtHeap(Heap *h);
void PrtHashTable(HashTable *);

Heap *HeapInit(int Size){
	Heap *h=malloc(sizeof(Heap));
	h->Size=Size;
	h->Elm=malloc(sizeof(ElementType)*(h->Size+1));
	h->Elm[0].Key=INT_MAX;		//哨兵
	return h;
}
void BuildHeap(Heap *h,int(*cmp)(ElementType,ElementType)){
	int father,son;
	ElementType x;
	for( int i=h->Size/2 ; i > 0 ; i-- ){
		x=h->Elm[i];
		father=i;
		son=father*2;
		while( son <= h->Size ){
			if( son < h->Size && cmp(h->Elm[son],h->Elm[son+1]) < 0
					&& cmp(x,h->Elm[son+1]) < 0 ){
				son=son+1;
				h->Elm[father]=h->Elm[son];
			}else if( cmp(h->Elm[son],x) > 0 ){
				h->Elm[father]=h->Elm[son];
			}else{
				break;
			}
			father=son;
			son=son*2;
		}
		h->Elm[father]=x;
	}
	return;
}
void HeapSort(Heap *h,int (*cmp)(ElementType,ElementType)){
	int Size=h->Size;
	ElementType x;
	while( Size ){
		x=h->Elm[Size];
		h->Elm[Size--]=h->Elm[1];
		int father,son;
		for( father=1,son=father*2 ; son <= Size ; father=son,son=son*2 ){
			if( son < Size && cmp(h->Elm[son],h->Elm[son+1]) < 0
					&& cmp( x , h->Elm[son+1] ) < 0 ){
				son=son+1;
				h->Elm[father]=h->Elm[son];
			}else if( cmp( h->Elm[son] , x ) > 0 ){
				h->Elm[father]=h->Elm[son];
			}else{
				break;
			}
		}
		h->Elm[father]=x;
	}
	return;
}
int HeapCmp(ElementType a,ElementType b){
	if( a.Key > b.Key )
		return 1;
	else if( a.Key == b.Key ) 
		return 0;
	else	
		return -1;
}
HashTable *HashTableInit(int TableSize){
	HashTable *h=malloc(sizeof(HashTable));
	h->TableSize=TableSize;
	h->Key= malloc(sizeof(ElementType)*h->TableSize);
	h->Info=malloc(sizeof(_Bool)*h->TableSize);
	memset(h->Info,EMPTY,sizeof(_Bool)*h->TableSize);
	return h;
}
int HashValue(HashTable *h,int key){
	return key%h->TableSize;
}
int InsertPos(HashTable *h,int key){
	int hv=HashValue(h,key);
	while( h->Info[hv] == OCCUPY ){
		hv=(hv+1)%h->TableSize;
	}
	return hv;
}
void Insert(HashTable *h,int index,int key){
	h->Key[index]=key;
	h->Info[index]=OCCUPY;
	return;
}
void PrtHeap(Heap *h){
	printf("Heap\n");
	printf("%-8s","Index:");
	for(int i=0;i<h->Size;i++)
		printf("%4d",i+1);
	printf("\n");
	printf("%-8s","Key:");
	for(int i=0;i<h->Size;i++)
		printf("%4d",h->Elm[i+1].Key);
	printf("\n");
	printf("%-8s","Pos:");
	for(int i=0;i<h->Size;i++)
		printf("%4d",h->Elm[i+1].Pos);
	printf("\n");
	printf("%-8s","Used:");
	for(int i=0;i<h->Size;i++)
		printf("%4s",h->Elm[i+1].Used?"Y":"N");
	printf("\n");
	return;
}
void PrtHashTable(HashTable *h){
	printf("Hash Table\n");
	printf("%-8s","Index:");
	for(int i=0;i<h->TableSize;i++){
		printf("%4d",i);
	}
	printf("\n");
	printf("%-8s","Key:");
	for(int i=0;i<h->TableSize;i++){
		printf("%4d",h->Key[i]);
	}
	printf("\n");
	printf("%-8s","Used:");
	for(int i=0;i<h->TableSize;i++){
		printf("%4s",h->Info[i]?"Y":"N");
	}
	printf("\n");
}

int main(void){
	int N;
	scanf("%d",&N);
	// Sort the Numbers
	Heap *h=HeapInit(N);
	int key;
	int Count=0;
	for(int i=0;i<N;i++){
		scanf("%d",&key);
		if( key >= 0 )
			h->Elm[++Count]=(ElementType){.Key=key,\
				.Pos=i,.Used=false};
	}
	h->Size=Count;		//	ignore the negative integer
	BuildHeap(h,HeapCmp);
	HeapSort(h,HeapCmp);
	//	-------------------------------------------
	HashTable *ht=HashTableInit(N);
	int prtC=0,pos;
	_Bool firstC=true;
	while( prtC != Count ){
//printf("Count :%d, prtC :%d\n",Count,prtC);
//PrtHeap(h);
//PrtHashTable(ht);
		//找到最小的没有使用过的key
		//这个key插入的位置是不是和输入的位置相同?
		//相同的话则输出该key,从头开始查找,prtC++,Used[i]=true
		//不同的话继续查找下一个最小的没有使用过的key
		for(int i=1;i<Count+1;i++){
			if( (h->Elm[i].Used == false) ){
				//sleep(5);
				pos=InsertPos(ht,h->Elm[i].Key);
				//printf("\n-----No.%d Key:%d Insert into:%d-----\n",i,h->Elm[i].Key,pos);
				if( pos == h->Elm[i].Pos ){
					if( firstC ){
						printf("%d",h->Elm[i].Key);
						firstC=false;
					}else
						printf(" %d",h->Elm[i].Key);
					h->Elm[i].Used=true;
					Insert(ht,h->Elm[i].Pos,h->Elm[i].Key);
					prtC++;
					break;
				}
			}
		}
	}
	return 0;
}
